package com.example.amap.baidu.map

import android.view.View
import com.baidu.mapapi.map.MapView
import com.baidu.mapapi.map.MyLocationConfiguration
import com.baidu.mapapi.map.MyLocationData
import com.example.amap.map.IMapView

class BaiDuMapView(private val mapView: MapView?) : IMapView {
    override fun getMapView(): View? {
        return mapView
    }

    override fun showMyLocationIcon() {
        mapView?.map?.apply {
            isMyLocationEnabled = true
            setMyLocationConfiguration(
                MyLocationConfiguration.Builder(
                    MyLocationConfiguration.LocationMode.NORMAL,
                    true
                ).build()
            )
        }
    }

    override fun onLocationUpdate(lon: Double, lat: Double, dir: Float) {
        mapView?.apply {
            val myLocation = MyLocationData.Builder()
                .latitude(lat)
                .longitude(lon)
                .direction(dir)
                .build()
            map?.setMyLocationData(myLocation)
        }
    }
}